package com.engein.mycolumn.config;

import com.engein.mycolumn.common.Constant;
import com.engein.mycolumn.interceptor.MyColumnLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyColumnWebMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private MyColumnLoginInterceptor myColumnLoginInterceptor;

    public void addInterceptors(InterceptorRegistry registry) {
        // 登陆拦截
        registry.addInterceptor(myColumnLoginInterceptor)
                .excludePathPatterns("/register")
                .excludePathPatterns("/login")
                .excludePathPatterns("/logout")
                .addPathPatterns("/columnPage")
                .addPathPatterns("/updateColumnInfo")
                .addPathPatterns("/myColumnPage")
                .addPathPatterns("/columnDetail/**")
                .addPathPatterns("/uploadFile")
                .addPathPatterns("/uploadFiles")
                .addPathPatterns("/articleEdit")
                .addPathPatterns("/articleEdit/**")
                .addPathPatterns("/article/**")
                .addPathPatterns("/updateUserInfo")
                .addPathPatterns("/personal");
    }

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + Constant.FILE_UPLOAD_DIC);
    }
}